#include <stdio.h>
#include <string.h>

/********************************************************************************
 * Problema da disciplina de Estrutura de Dados e Complexidade de Algoritmos da *
 * Pos Graduacao do Periodo 2011.1                                              *
 *                                                                              *
 * @see https://br.spoj.pl/problems/PEDAGIO/                                    *
 * @author Elenilson Vieira - 111100371 - elenilson[at]elenilsonvieira.com      *
 * @since 12 de junho de 2011                                                   *
 ********************************************************************************/
int main() {
    int citiesAmount, roadsAmount, jucaCity, maxToll, x, y, testNumber = 1, i;
    char graph[50][50];

    while (scanf("%d %d %d %d", &citiesAmount, &roadsAmount, &jucaCity, &maxToll) == 4 &&
            citiesAmount != 0 && roadsAmount != 0 && jucaCity != 0 && maxToll != 0) {
        memset(graph, 0, sizeof (graph));

        while (roadsAmount--) {
            scanf("%d %d", &x, &y);
            graph[x - 1][y - 1] = graph[y - 1][x - 1] = 1;
        }

        int j = 0;
        int citiesToVisit[citiesAmount];
        int levelCities[citiesAmount];
        for (i = 0; i < citiesAmount; i++) {
            citiesToVisit[i] = 0;
            levelCities[i] = 0;
        }

        levelCities[jucaCity - 1] = 1;

        /*** Bota a cidade de juquinha como primeiro nivel a ser varrido ***/
        int nextLevelCities[citiesAmount];
        for (j = 0; j < citiesAmount; j++)
            nextLevelCities[j] = 0;

        for (i = 0; i < maxToll; i++) {

            int levelCity = 0;
            for (levelCity = 0; levelCity < citiesAmount; levelCity++) {
                /*** Se for para verificar as rotas dessa cidade, ou seja, to no nivel dela ***/
                if (levelCities[levelCity]) {
                    /*** Vejo as rotas da cidade ***/
                    for (j = 0; j < citiesAmount; j++) {
                        /***
                         * Se tem uma rota para a cidade de indice j, adiciona j
                         * no proximo nivel e j como sendo uma cidade a ser visitada
                         ***/
                        if (graph[levelCity][j] && j + 1 != jucaCity) {
                            citiesToVisit[j] = 1;
                            nextLevelCities[j] = 1;
                        }
                    }
                }
            }

            /*** Copia o nextLevel para o levelAtual e limpa o nextLevel ***/
            for (j = 0; j < citiesAmount; j++) {
                levelCities[j] = nextLevelCities[j];
                nextLevelCities[j] = 0;
            }
        }

        printf("Teste %d\n", testNumber++);
        for (i = 0; i < citiesAmount; i++)
            if (i + 1 != jucaCity && citiesToVisit[i])
                printf("%d ", i + 1);
        printf("\n\n");
    }
    
    return 0;
}

